import * as fs from "node:fs"
import { savePng, loadPng, Pixel } from '../index.js';

const W = 300;
const H = 300;

const R = 100;

const CX1 = 150;
const CY1 = 100;

const CX2 = 100;
const CY2 = 200;

const CX3 = 200;
const CY3 = 200;

export function testPng(){
    const pixels:Pixel[] = []
    for(let y=0; y<H; y++){
        for(let x=0; x<W; x++){
            const index = y*W+x;
            const p = {
                r: 0,
                g: 0,
                b: 0,
                a: 0
            }
            if((x-CX1)*(x-CX1)+(y-CY1)*(y-CY1)<=R*R){
                p.r = 255;
                p.a = 255;
            }
            if((x-CX2)*(x-CX2)+(y-CY2)*(y-CY2)<=R*R){
                p.g = 255;
                p.a = 255;
            }
            if((x-CX3)*(x-CX3)+(y-CY3)*(y-CY3)<=R*R){
                p.b = 255;
                p.a = 255;
            }
            pixels[index] = p;
        }
    }
    const testFile = "D:\\test\\test.png";
    const testJsonFile = "D:\\test\\test.json";
    savePng(W,H,pixels,testFile);
    fs.writeFileSync(testJsonFile,JSON.stringify(loadPng(testFile)));
}
